package com.wshare.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;

@Entity
@Table(name = "role")
public class Role {
	
	@Id
	@GenericGenerator(name="increment" , strategy="increment")
	@GeneratedValue(generator="increment")
	@Column(name= "rol_id")
	private int rolId;
	
	@Column(name = "rol_name")
	private String rolName;
	
	@ManyToMany(mappedBy="lRoles")
	@JsonBackReference
	private List<Account> lAccounts; 
	
	@ManyToMany
	@JoinTable(name = "role_permission",joinColumns={@JoinColumn(name = "rol_id")},inverseJoinColumns={@JoinColumn(name = "per_id")})
	@Cascade({CascadeType.DELETE})
	@LazyCollection(LazyCollectionOption.FALSE)
	@JsonManagedReference
	private List<Permission> lPermissions;

	public Role() {
	}

	public Role(int rolId, String rolName, List<Account> lAccounts,
			List<Permission> lPermissions) {
		this.rolId = rolId;
		this.rolName = rolName;
		this.lAccounts = lAccounts;
		this.lPermissions = lPermissions;
	}

	public int getRolId() {
		return rolId;
	}

	public void setRolId(int rolId) {
		this.rolId = rolId;
	}

	public String getRolName() {
		return rolName;
	}

	public void setRolName(String rolName) {
		this.rolName = rolName;
	}

	public List<Account> getlAccounts() {
		return lAccounts;
	}

	public void setlAccounts(List<Account> lAccounts) {
		this.lAccounts = lAccounts;
	}

	public List<Permission> getlPermissions() {
		return lPermissions;
	}

	public void setlPermissions(List<Permission> lPermissions) {
		this.lPermissions = lPermissions;
	}
	
	
	
	
}